//用于存储token和权限校验
import Cookies from 'js-cookie'

const TokenKey = 'USER-TOKEN'
const UserNameKey = 'USER-NAME'
const UserImageKey = 'USER-IMAGE'
const UserId = 'USER-ID'

//保存用户
export function setUser(token, username, user_image, uid) {
    Cookies.set(TokenKey, token,{ expires: 1, path: '/' });
    Cookies.set(UserNameKey, username,{ expires: 1, path: '/' } );
    Cookies.set(UserImageKey, user_image,{ expires: 1, path: '/' });
    Cookies.set(UserId, uid,{ expires: 1, path: '/' });
}

//得到用户信息
export function getUser() {
    return {
        token: Cookies.get(TokenKey),
        username: Cookies.get(UserNameKey),
        userImage: Cookies.get(UserImageKey),
        uid: Cookies.get(UserId)
    }
}

//退出登录
export function removeUser() {
    Cookies.remove(TokenKey);
    Cookies.remove(UserNameKey);
    Cookies.remove(UserImageKey);
    Cookies.remove(UserId);
}

